package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.*;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Objects;

public class RentBoundaryAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    @Autowired
    IQuerySceneInstService querySceneInstService;

    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
        super.after(attr, inst, data);
        String sceneInstId = data.getSceneInstId();
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(sceneInstId);
        KiteOfferInst offerInst = querySceneInstService.getOfferInst(data.getCustId(), sceneInst.getRootInstId());
        List<KiteAttrValue> attrValues = attr.getAttrValues();
        KiteAttrValue attrValue = null;
        if ("50041903".equals(offerInst.getSpecId())) {
            // 省内长途
            attrValue = attrValues.stream().filter(spec -> "1_0000114".equals(spec.getAttrValue())).findFirst().orElse(null);
        }
        else if ("50041904".equals(offerInst.getSpecId())) {
            // 本地
            attrValue = attrValues.stream().filter(spec -> "1_0000111".equals(spec.getAttrValue())).findFirst().orElse(null);
        }
        if (Objects.nonNull(attrValue)) {
            attr.setValue(attrValue.getAttrValue());
            attr.setValueDesc(attrValue.getAttrValueName());
        }
    }
}
